﻿Imports System.Collections.Generic
Imports System.Data
Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL
Imports System.Xml

Public Class BusquedaTarifa
    Inherits System.Web.UI.Page
    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ListarTarifas()
        End If
    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarTarifas()
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub

    Private Sub ListarTarifas()

        Dim objTarifaBE As New TarifaBE
        Dim objUtil As New Funciones

        If txtCodigo.Text.Trim <> "" Then
            objTarifaBE.Codigo = objUtil.ReemplazarTexto(txtCodigo.Text.Trim)
            objTarifaBE.Descripcion = IIf(txtDescripcion.Text = String.Empty, "", objUtil.ReemplazarTexto(txtDescripcion.Text.Trim))
        ElseIf txtDescripcion.Text.Trim <> "" Then
            objTarifaBE.Codigo = IIf(txtCodigo.Text = String.Empty, "", objUtil.ReemplazarTexto(txtCodigo.Text.Trim))
            objTarifaBE.Descripcion = objUtil.ReemplazarTexto(txtDescripcion.Text.Trim)
        Else
            objTarifaBE.Codigo = ""
            objTarifaBE.Descripcion = ""
        End If

        Dim objTarifaBC As New TarifaBC
        dtgTarifa.DataSource = objTarifaBC.ListadoTarifas(objTarifaBE)
        dtgTarifa.DataBind()

        If dtgTarifa.Rows.Count <= 0 Then
            dtgTarifa.Visible = False
            lblError.Visible = True
        Else
            dtgTarifa.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click
        Dim dt As New DataTable
        Dim sCodigo As String = String.Empty
        Dim sDescripcion As String = String.Empty
        Dim scadena As String

        For Each Me.itemgridview In dtgTarifa.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                sCodigo = CType(itemgridview.FindControl("lblcodigo"), Label).Text
                sDescripcion = CType(itemgridview.FindControl("lblDescripcion"), Label).Text
            End If

        Next
        scadena = sDescripcion

        If sDescripcion.ToString.Trim = "" Then
            Session("BPDesTarifa") = ""
            Session("BPCodTarifa") = ""
            Exit Sub
        End If
        '  Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BPCodTarifa") = sCodigo
        Session("BPDesTarifa") = sDescripcion

    End Sub


    Sub Cambiarpagina(ByVal sender As Object, ByVal e As GridViewPageEventArgs)



        Dim objTarifaBE As New TarifaBE
        Dim objUtil As New Funciones

        If txtCodigo.Text.Trim <> "" Then
            objTarifaBE.Codigo = objUtil.ReemplazarTexto(txtCodigo.Text.Trim)
            objTarifaBE.Descripcion = IIf(txtDescripcion.Text = String.Empty, "", objUtil.ReemplazarTexto(txtDescripcion.Text.Trim))
        ElseIf txtDescripcion.Text.Trim <> "" Then
            objTarifaBE.Codigo = IIf(txtCodigo.Text = String.Empty, "", objUtil.ReemplazarTexto(txtCodigo.Text.Trim))
            objTarifaBE.Descripcion = objUtil.ReemplazarTexto(txtDescripcion.Text.Trim)
        Else
            objTarifaBE.Codigo = ""
            objTarifaBE.Descripcion = ""
        End If

        Dim objTarifaBC As New TarifaBC
        dtgTarifa.PageIndex = e.NewPageIndex
        dtgTarifa.DataSource = objTarifaBC.ListadoTarifas(objTarifaBE)
        dtgTarifa.DataBind()

        If dtgTarifa.Rows.Count <= 0 Then
            dtgTarifa.Visible = False
            lblError.Visible = True
        Else
            dtgTarifa.Visible = True
            lblError.Visible = False
        End If

    End Sub

End Class